package com.binarysoft.service.obj.dao;

import java.util.Collection;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface ObjectEntityMapper {
	@Delete({ "delete from object_entity", "where obj_id = #{objId,jdbcType=INTEGER}" })
	int deleteByPrimaryKey(long objId);

	@Insert({ "insert into object_entity (obj_id, obj_name, ", "obj_desc, obj_addr, ", "parent_obj_id, root_obj_id, ", "obj_hierarchy, obj_index, ", "obj_type_id, is_active, ",
			"creation_time, last_updated_time)", "values (#{objId,jdbcType=INTEGER}, #{objName,jdbcType=VARCHAR}, ", "#{objDesc,jdbcType=VARCHAR}, #{objAddr,jdbcType=VARCHAR}, ",
			"#{parentObjId,jdbcType=INTEGER}, #{rootObjId,jdbcType=INTEGER}, ", "#{objHierarchy,jdbcType=INTEGER}, #{objIndex,jdbcType=VARCHAR}, ",
			"#{objTypeId,jdbcType=VARCHAR}, #{isActive,jdbcType=BIT}, ", "#{creationTime,jdbcType=DATE}, #{lastUpdatedTime,jdbcType=DATE})" })
	int insert(ObjectEntity record);

	@Insert({ 
		"insert into object_entity (obj_id, obj_name, ", "obj_desc, obj_addr, ", "parent_obj_id, root_obj_id, ", "obj_hierarchy, obj_index, ", "obj_type_id, is_active, ",
			"creation_time, last_updated_time)", 
			
			"values (#{objId,jdbcType=INTEGER}, #{objName,jdbcType=VARCHAR}, ", "#{objDesc,jdbcType=VARCHAR}, #{objAddr,jdbcType=VARCHAR}, ",
			"#{parentObjId,jdbcType=INTEGER}, #{rootObjId,jdbcType=INTEGER}, ", "#{objHierarchy,jdbcType=INTEGER}, #{objIndex,jdbcType=VARCHAR}, ",
			"#{objTypeId,jdbcType=VARCHAR}, #{isActive,jdbcType=BIT}, ", "#{creationTime,jdbcType=DATE}, #{lastUpdatedTime,jdbcType=DATE})" })
	int insert(Collection<ObjectEntity> records);

	@InsertProvider(type = ObjectEntitySqlProvider.class, method = "insertSelective")
	int insertSelective(ObjectEntity record);

	@Select({ "select", "obj_id, obj_name, obj_desc, obj_addr, parent_obj_id, root_obj_id, obj_hierarchy, ", "obj_index, obj_type_id, is_active, creation_time, last_updated_time",
			"from object_entity", "where obj_id = #{objId,jdbcType=INTEGER}" })
	@Results({ @Result(column = "obj_id", property = "objId", jdbcType = JdbcType.INTEGER, id = true), @Result(column = "obj_name", property = "objName", jdbcType = JdbcType.VARCHAR),
			@Result(column = "obj_desc", property = "objDesc", jdbcType = JdbcType.VARCHAR), @Result(column = "obj_addr", property = "objAddr", jdbcType = JdbcType.VARCHAR),
			@Result(column = "parent_obj_id", property = "parentObjId", jdbcType = JdbcType.INTEGER), @Result(column = "root_obj_id", property = "rootObjId", jdbcType = JdbcType.INTEGER),
			@Result(column = "obj_hierarchy", property = "objHierarchy", jdbcType = JdbcType.INTEGER), @Result(column = "obj_index", property = "objIndex", jdbcType = JdbcType.VARCHAR),
			@Result(column = "obj_type_id", property = "objTypeId", jdbcType = JdbcType.VARCHAR), @Result(column = "is_active", property = "isActive", jdbcType = JdbcType.BIT),
			@Result(column = "creation_time", property = "creationTime", jdbcType = JdbcType.DATE), @Result(column = "last_updated_time", property = "lastUpdatedTime", jdbcType = JdbcType.DATE) })
	ObjectEntity selectByPrimaryKey(long objId);

	@UpdateProvider(type = ObjectEntitySqlProvider.class, method = "updateByPrimaryKeySelective")
	int updateByPrimaryKeySelective(ObjectEntity record);

	@Update({ "update object_entity", "set obj_name = #{objName,jdbcType=VARCHAR},", "obj_desc = #{objDesc,jdbcType=VARCHAR},", "obj_addr = #{objAddr,jdbcType=VARCHAR},",
			"parent_obj_id = #{parentObjId,jdbcType=INTEGER},", "root_obj_id = #{rootObjId,jdbcType=INTEGER},", "obj_hierarchy = #{objHierarchy,jdbcType=INTEGER},",
			"obj_index = #{objIndex,jdbcType=VARCHAR},", "obj_type_id = #{objTypeId,jdbcType=VARCHAR},", "is_active = #{isActive,jdbcType=BIT},", "creation_time = #{creationTime,jdbcType=DATE},",
			"last_updated_time = #{lastUpdatedTime,jdbcType=DATE}", "where obj_id = #{objId,jdbcType=INTEGER}" })
	int updateByPrimaryKey(ObjectEntity record);
}